#include "StdAfx.h"
#include "ZWuliuDefine.h"
	
	
	

bool ZWuliuGlobalTools::Str2WuliuRecords( const QString& sCommonDataStr, std::vector<ZDbRecord*>& reVal )
{
	vecStr subStrs = ZGlobalTool::SplitStr_NoTrim(sCommonDataStr, ZSplitStr_1);
	if (subStrs.size() != 2)
	{
		return false;
	}

	QString sClassName = subStrs[0];
	QString sAllRecordStr = subStrs[1];
	vecStr vecRecordStr = ZGlobalTool::SplitStr_NoTrim(sAllRecordStr, ZSplitStr_2);

	for (auto it=vecRecordStr.begin(); it!=vecRecordStr.end(); it++)
	{
		ZDbRecord* pNewItem = dynamic_cast<ZDbRecord*>(ZObject::CreateObjFromName(sClassName));
		if (pNewItem)
		{
			if(pNewItem->SetDataByStr(*it))
			{
				reVal.push_back(pNewItem);
			}
			else
			{
				delete pNewItem;
			}
		}
	}

	return true;
}

QString ZWuliuGlobalTools::WuliuRecords2Str( ZDbRecord* pRecord )
{
	vecDBRecordPtrs vecRecords;
	vecRecords.push_back(pRecord);
	return WuliuRecords2Str(vecRecords);
}

QString ZWuliuGlobalTools::WuliuRecords2Str( const vecDBRecordPtrs& vecRecords )
{
	if (vecRecords.empty())
	{
		return "";
	}

	QString sAllStr = vecRecords.front()->GetClassName_Z() + ZSplitStr_1;
	for (int i=0; i<vecRecords.size(); i++)
	{
		if (i+1 == vecRecords.size())
		{
			sAllStr += vecRecords[i]->ToString();
		}
		else
		{
			sAllStr += vecRecords[i]->ToString() + ZSplitStr_2;
		}
	}

	return sAllStr;
}

